#include "KitMock.h"
#include "Part.h"


KitMock::KitMock()
{
	parts = new std::vector<Part*>(8);
	number_parts = 0;
}

KitMock::~KitMock()
{
}

void KitMock::addPart(Part *p)
{
	parts->push_back(p);
	number_parts++;
}

void KitMock::addPart(Part *p, int ind)
{
	if(parts->at(ind) == NULL)
		number_parts++;
	//Sean says: you must make yourself the parent of the part I add to you
	parts->at(ind) = p;
}

Part* KitMock::getPart(int ind)
{
	return parts->at(ind);
}

bool KitMock::isComplete()
{
	bool complete = true;
	bool partExists = false;
	std::vector<bool> partsUsed(parts->size()); //make sure a single part isn't counted twice
	if ( parts->size() < partTypesNeeded.size() )
	{
		complete = false;
	}
	else 
	{
		for ( int i = 0; i < partTypesNeeded.size(); ++i ) // Alex says: why ++i, shouldn't it be i++ ?
		{
			partExists = false;
			for ( int j = 0; j < parts->size(); ++j )
			{
				if ( parts->at( j )->type() == partTypesNeeded.at( i ) && !partsUsed.at( j ) )
				{
					partExists = true;
					partsUsed.at( j ) = true;
					break;
				}
			}
			if ( !partExists )
			{
				complete = false;
				break;
			}
		}
	}

	return complete;
}

void KitMock::removePart(int ind)
{
	if(parts->at(ind) != NULL)
	{
		parts->at(ind) = NULL;
		number_parts--;
	}
}

std::vector<PartType> KitMock::getPartTypesNeeded()
{
	return this->partTypesNeeded;
}

bool KitMock::isFull()
{
	return (number_parts !=0 );
}